home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / JFC.bin / MotifSplitPaneDivider.java < prev    next >
Text File  |  1998-06-30  |  5KB  |  156 lines

  1. /*
  2.  * @(#)MotifSplitPaneDivider.java    1.6 98/02/02
  3.  * 
  4.  * Copyright (c) 1997 Sun Microsystems, Inc. All Rights Reserved.
  5.  * 
  6.  * This software is the confidential and proprietary information of Sun
  7.  * Microsystems, Inc. ("Confidential Information").  You shall not
  8.  * disclose such Confidential Information and shall use it only in
  9.  * accordance with the terms of the license agreement you entered into
  10.  * with Sun.
  11.  * 
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
  13.  * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  14.  * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  15.  * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
  16.  * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
  17.  * THIS SOFTWARE OR ITS DERIVATIVES.
  18.  * 
  19.  */
  20.  
  21. package com.sun.java.swing.plaf.motif;
  22.  
  23. import java.awt.*;
  24. import com.sun.java.swing.JSplitPane;
  25. import com.sun.java.swing.UIManager;
  26. import com.sun.java.swing.plaf.basic.BasicSplitPaneUI;
  27. import com.sun.java.swing.plaf.basic.BasicSplitPaneDivider;
  28.  
  29.  
  30. /**
  31.  * Divider used for Motif split pane.
  32.  * <p>
  33.  * Warning: serialized objects of this class will not be compatible with
  34.  * future swing releases.  The current serialization support is appropriate
  35.  * for short term storage or RMI between Swing1.0 applications.  It will
  36.  * not be possible to load serialized Swing1.0 objects with future releases
  37.  * of Swing.  The JDK1.2 release of Swing will be the compatibility
  38.  * baseline for the serialized form of Swing objects.
  39.  *
  40.  * @version 1.6 02/02/98
  41.  * @author Jeff Dinkins
  42.  */
  43. public class MotifSplitPaneDivider extends BasicSplitPaneDivider
  44. {
  45.  
  46.     public static final int minimumThumbSize = 6;
  47.     public static final int defaultDividerSize = 18;
  48.  
  49.     protected  static final int pad = 6;
  50.  
  51.     protected int hThumbWidth = 12;
  52.     protected int hThumbHeight = 18;
  53.     protected int vThumbWidth = 18;
  54.     protected int vThumbHeight = 12;
  55.  
  56.     protected Color highlightColor;
  57.     protected Color shadowColor;
  58.  
  59.     /**
  60.      * Creates a new Motif SplitPaneDivider
  61.      */
  62.     public MotifSplitPaneDivider(BasicSplitPaneUI ui) {
  63.     super(ui);
  64.     highlightColor = UIManager.getColor("SplitPane.highlight");
  65.     shadowColor = UIManager.getColor("SplitPane.shadow");
  66.     setDividerSize(hThumbWidth + pad);
  67.     }
  68.  
  69.     /**
  70.      * overrides to hardcode the size of the divider
  71.      * PENDING(jeff) - rewrite JSplitPane so that this ins't needed
  72.      */
  73.     public void setDividerSize(int newSize) {
  74.         if (newSize < pad + minimumThumbSize) {
  75.             setDividerSize(pad + minimumThumbSize);
  76.         } else {
  77.             vThumbHeight = hThumbWidth = newSize - pad;
  78.             super.setDividerSize(newSize);
  79.         }                  
  80.     }
  81.  
  82.     /**
  83.       * Paints the divider.
  84.       */
  85.     // PENDING(jeff) - the thumb's location and size is currently hard coded. It
  86.     // should be dynamic.
  87.     public void paint(Graphics g) {
  88.     Color               bgColor = getBackground();
  89.     Dimension           size = getSize();
  90.  
  91.     // fill
  92.     g.setColor(getBackground());
  93.     g.fillRect(0, 0, size.width, size.height);
  94.  
  95.     if(getBasicSplitPaneUI().getOrientation() == JSplitPane.HORIZONTAL_SPLIT) {
  96.         int center = size.width/2;
  97.         int x = size.width/2 - hThumbWidth/2;
  98.         int y = 30;  // PENDING(jeff) - don't hard code this.
  99.  
  100.         // split line
  101.         g.setColor(shadowColor);
  102.         g.drawLine(center-1, 0, center-1, size.height);
  103.  
  104.         g.setColor(highlightColor);
  105.         g.drawLine(center, 0, center, size.height);
  106.  
  107.         // draw thumb
  108.         g.setColor(getBackground());
  109.         g.fillRect(x+1, y+1, hThumbWidth-2, hThumbHeight-1);
  110.  
  111.         g.setColor(highlightColor);
  112.         g.drawLine(x, y, x+hThumbWidth-1, y);                                 // top
  113.         g.drawLine(x, y+1, x, y+hThumbHeight-1);                              // left
  114.  
  115.         g.setColor(shadowColor);
  116.         g.drawLine(x+1, y+hThumbHeight-1, x+hThumbWidth-1, y+hThumbHeight-1); // bottom
  117.         g.drawLine(x+hThumbWidth-1, y+1, x+hThumbWidth-1, y+hThumbHeight-2);  // right
  118.  
  119.     } else {
  120.         int center = size.height/2;
  121.         int x = size.width - 40; // PENDING(jeff) - don't hard code this
  122.         int y = size.height/2 - vThumbHeight/2;
  123.  
  124.         // split line
  125.         g.setColor(shadowColor);
  126.         g.drawLine(0, center-1, size.width, center-1);
  127.  
  128.         g.setColor(highlightColor);
  129.         g.drawLine(0, center, size.width, center);
  130.  
  131.         // draw thumb
  132.         g.setColor(getBackground());
  133.         g.fillRect(x+1, y+1, vThumbWidth-1, vThumbHeight-1);
  134.  
  135.         g.setColor(highlightColor);
  136.         g.drawLine(x, y, x+vThumbWidth, y);    // top
  137.         g.drawLine(x, y+1, x, y+vThumbHeight); // left
  138.  
  139.         g.setColor(shadowColor);
  140.         g.drawLine(x+1, y+vThumbHeight, x+vThumbWidth, y+vThumbHeight);  // bottom
  141.         g.drawLine(x+vThumbWidth, y+1, x+vThumbWidth, y+vThumbHeight-1); // right
  142.     }
  143.         super.paint(g);
  144.  
  145.     }
  146.  
  147.     /**
  148.       * The minimums size is the same as the preferredSize
  149.       */
  150.     public Dimension getMinimumSize() {
  151.     return getPreferredSize();
  152.     }
  153.  
  154.  
  155. }
  156.